package com.qd.panda.commodity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.commodity.CommodityDTO;
import com.qd.panda.service.commodity.CommodityService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * 商城/商品信息/APP_商品信息
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/app/commodity/")
@Slf4j
public class AppCommodityController {
    private final CommodityService commodityService;

    /**
     * 详情
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/getById")
    public CommodityDTO getById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return commodityService.getByIdDto(id);
    }

    /**
     * 列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/page")
    public IPage<CommodityDTO> page(CommodityDTO dto) {
        return commodityService.appPage(PageUtil.buildPage(dto), dto);
    }
}